use crate::schema::posts;
use common::pagination::PaginationForm;

#[derive(Queryable)]
#[derive(Serialize)]
pub struct Post {
    pub id: i32,
    pub title: String,
    pub body: String,
    pub published: bool,
}

#[derive(FromForm)]
pub struct PostPage {
    pub page_index: i64,
    pub page_size: i64,
    pub title: String
}
impl PaginationForm for PostPage {
    fn get_page_index(&self) -> i64 {
       self.page_index
    }

    fn get_page_size(&self) -> i64 {
        self.page_size
    }
}

#[derive(Insertable)]
#[derive(Deserialize)]
#[derive(Debug)]
#[table_name="posts"]
pub struct PostNew {
    pub title: String,
    pub body: String,
    pub published: bool,
}

#[derive(Deserialize)]
#[derive(Debug)]
pub struct PostUpdate {
    pub id: i32,
    pub title: String,
    pub body: String,
    pub published: bool,
}
